<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      body, html,#allmap {
        width: 100%;
        height: 100%;
        overflow: hidden;
        margin:0;
        font-family:"微软雅黑";
      }
    </style>
    <script
      type="text/javascript"
      src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=oyva8hEbGyySeHenlvpaPYgbblTWU2mA"
    ></script>
    <title>地图展示</title>
  </head>
  <body>
    <div id="allmap"></div>
  </body>
</html>
<script type="text/javascript">
  var map = new BMapGL.Map("allmap");
  var point = new BMapGL.Point(116.331398,39.897445);
  map.centerAndZoom(point,15);
   map.enableScrollWheelZoom(true);
   
   var geolocation = new BMapGL.Geolocation();
  var geoc = new BMapGL.Geocoder();
  geolocation.getCurrentPosition(function(r){
      if(this.getStatus() == BMAP_STATUS_SUCCESS){
          var mk = new BMapGL.Marker(r.point);
          map.addOverlay(mk);
          map.panTo(r.point);
          map.centerAndZoom(r.point,15);
          console.log('您的位置：' + r.point.lng + ',' + r.point.lat);
          // 根据point得到对应的adress名称
          geoc.getLocation(r.point, function(rs){
            var addComp = rs.addressComponents;
            alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber)
          })
      }
      else {
          alert('failed' + this.getStatus());
      }
  });
</script>
